﻿@{
    Layout = "~/Views/Shared/_wxDetail.cshtml";

    if (false)
    {
        <script src="~/LiberUI/Scripts/jquery.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Base.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Action.js"></script>
    }
}
<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <meta name="renderer" content="webkit">
    <title>销售-订单详情</title>
    <link href="/SiteUI/Base.css" rel="stylesheet" />
    <link href="/SiteUI/Trade/OrderDetail.css" rel="stylesheet" />
    <script src="/LiberUI/Scripts/laytpl.js"></script>

</head>
<body>
    <div class="view screen">
        <div class="row">
            <div class="clo-sm-12 detail">

            </div>
        </div>
        <div class="row foot" obj-auth="true" obj-role="saler|buyer">
            <div class="col-sm-6 button" obj-auth="true" obj-role="saler" id="btnConfirmOrder">
                确认订单
            </div>
            <div class="col-sm-12 button" obj-auth="true" obj-role="buyer" execute="remove" id="btnRemindSaler">
                提醒卖方确认
            </div>
            <div class="col-sm-6">
                @*<a obj-role="buyer" id="lnkAllNewPurchaseOrders" class="LinkTo" href="/Purchase/WxMyOrders?openuid="><i class="soicon icon-list"></i>我的全部订单</a>*@
                <a obj-auth="true" obj-role="saler" id="lnkAllNewSaleOrders" class="LinkTo" href="/Sale/WxMyOrders"><i class="soicon icon-list"></i>更多新订单</a>
            </div>
        </div>
    </div>
    <script id="tplOrderDetail" type="text/html">
        <div class="row" id="orderHead">
            <div class="col-sm-12">
                <h4>交易编号：<strong id="oh-id">{{d.idstr}}</strong></h4>
            </div>
            <div class="col-sm-12" obj-auth="true">
                <h4>总金额：<strong id="oh-amount">{{d.amountstr}}</strong></h4>
            </div>
            <div class="col-sm-12">
                <h4>状态:<span id="oh-status" class="Pendding"><i>订单状态</i></span></h4>
            </div>
            <div class="col-sm-12">
                <h5>客户订单：<strong id="oh-clnt-serial"></strong></h5>
            </div>
            <div class="col-sm-12">
                <h5>订货日期：<strong id="oh-order-date">00001</strong></h5>
            </div>
        </div>

        <!--订单进度-->
        <div class="row" id="orderProcess">
            <div class="col-sm-12">
                <h5>交付进度</h5>
                <div id="orderDelivery">
                    <span>已发货：</span>
                    <span>已入库：</span>
                </div>
            </div>
            <div class="col-sm-12">
                <h5>付款进度</h5>
                <div id="orderPay">
                    -
                </div>
            </div>
        </div>
        <!--订单详情-->
        <div class="row">
            <div class="col-sm-12" id="tradeInfo">
                <div class="row">
                    <div class="col-sm-12 InfoBlock" obj-auth="true" obj-role="buyer|consignee">
                        <h5>供应商信息</h5>
                        <div class="DataField">
                            <span class="df-title">供&nbsp;&nbsp;应&nbsp;&nbsp;商：</span>
                            {{#if(d.supplier_realname){ }}
                            <span class="df-value"><a href="/Company/WxPortal?oid={{d.supplier_idstr}}">{{d.supplier_realname}}</a></span>
                            {{#}else{ }}
                            <span class="df-value"><a href="#">{{d.src_supplier}}</a></span>
                            {{#} }}
                        </div>
                        <div class="DataField">
                            <span class="df-title">联&nbsp;&nbsp;系&nbsp;&nbsp;人：</span>
                            {{#if(d.saler_realname){ }}
                            <span class="df-value"><a class="People certificated" href="#">{{d.saler_realname}}</a></span>
                            {{#}else{ }}
                            <span class="df-value"><a class="People no-certificated" href="#">{{d.src_saler}}</a></span>
                            {{#} }}
                        </div>
                        <div class="DataField">
                            <span class="df-title">联系方式：</span>
                            <span class="df-value">{{d.saler_phone}}</span>
                        </div>
                    </div>
                    <div class="col-sm-12 InfoBlock" obj-auth="true" obj-role="saler">
                        <h5>采购方信息</h5>
                        <div class="DataField">
                            <span class="df-title">采购单位：</span>
                            {{#if(d.client_realname){ }}
                            <span class="df-value"><a href="/Company/WxPortal?oid={{d.client_idstr}}">{{d.client_realname}}</a></span>
                            {{#}else{ }}
                            <span class="df-value"><a href="#">{{d.src_client}}</a></span>
                            {{#} }}
                        </div>
                        <div class="DataField">
                            <span class="df-title">联&nbsp;&nbsp;系&nbsp;&nbsp;人：</span>
                            {{#if(d.buyer_realname){ }}
                            <span class="df-value"><a href="#" class="People certificated">{{d.buyer_realname}}</a></span>
                            {{#}else{ }}
                            <span class="df-value"><a href="#">{{d.src_buyer}}</a></span>
                            {{#} }}
                        </div>
                        <div class="DataField">
                            <span class="df-title">联系方式：</span>
                            <span class="df-value">{{d.buyer_phone}}</span>
                        </div>
                    </div>
                    <div class="col-sm-12 InfoBlock">
                        <h5>交付信息</h5>
                        <div class="DataField">
                            <span class="df-title">收&nbsp;&nbsp;货&nbsp;&nbsp;人：</span>
                            <span class="df-value">
                                <span>{{d.consignee_displayname}}</span>
                                <span>{{d.consignee_phone}}</span>
                            </span>
                        </div>
                        <div class="DataField">
                            <span class="df-title">交付方式：</span>
                            <span class="df-value">{{d.deliverymode}}</span>
                        </div>
                        <div class="DataField">
                            <span class="df-title">送货地址：</span>
                            <span class="df-value">{{d.src_dlvaddress}}</span>
                        </div>
                        <div class="DataField">
                            <span class="df-title">送货时间：</span>
                            {{#if(d._urgent){ }}
                            <span class="df-value urgent" title="交货日期已临近，请注意跟进">{{d._dlvDate}}<i class="icon-erroroutline"></i></span>
                            {{#}else{ }}
                            <span class="df-value">{{d._dlvDate}}</span>
                            {{#} }}
                        </div>
                        <div class="DataField">
                            <span class="df-title">质保条件</span>
                            <span class="df-value">{{d.qualityguarantee}}</span>
                        </div>
                    </div>
                    <div class="col-sm-12 InfoBlock" obj-auth="true" obj-role="buyer|saler">
                        <h5>支付和发票信息</h5>
                        <div class="DataField">
                            <span class="df-title">支付方式：</span>
                            <span class="df-value">{{d.settlement}}</span>
                        </div>
                        <div class="DataField">
                            <span class="df-title">发票抬头：</span>
                            <span class="df-value">{{d.invoiceheading}}</span>
                        </div>
                        <div class="DataField">
                            <span class="df-title">发票类型：</span>
                            <span class="df-value">{{d.invoicetype}}</span>
                        </div>
                        <div class="DataField">
                            <span class="df-title">税&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;率：</span>
                            <span class="df-value">{{d.taxrate}}</span>
                        </div>
                        <div class="DataField">
                            <span class="df-title">发票内容：</span>
                            <span class="df-value">{{d.invoicemx}}</span>
                        </div>
                    </div>
                    <div class="col-sm-12 InfoBlock">
                        <h5>其他信息</h5>
                        {{#if(d.src_orderserial){ }}
                        <div class="DataField">
                            <span class="df-title">客户订单：</span>
                            <span class="df-value">{{d.src_orderserial}}</span>
                        </div>
                        {{#} }}
                        <div class="DataField">
                            <span class="df-title">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：</span>
                            <span class="df-value">{{d.memo}}</span>
                        </div>
                    </div>
                </div>
            </div>
        </div> 

        <!--订单明细-->
        <div class="InfoSection row expand" id="orderItems">
            <div class="InfoSectionTitle">
                <i class="soicon "></i><span>商品明细</span>
            </div>
            <div class="InfoSectionBody">
                <ol></ol>
                <li class="wx-order-item-tpl">
                    <h5 class="oi-title"></h5>
                    <span class="oi-model"></span>
                    <br />
                    <span class="oi-productSpec"></span>
                    <div class="oi-mx-countinfo">
                        <span class="oi-mx-price">单价：</span>
                        <span class="oi-storage">入库：-</span>
                        <br />
                        <span class="oi-mx-count">数量：</span>
                        <span class="oi-mx-amount">小计：</span>
                    </div>
                    <div class="floatClear">

                    </div>
                </li>
            </div>
        </div>
    </script>
    <script>
        var order = null;
        var tplNO = null;
        var btnConfirmOrder = null;
        var btnRemindSaler = null;

        function renderOrder(od) {
            if (od.src_orderserial) {
                if (od.src_orderversion) {
                    od.src_orderserial += '[' + od.src_orderversion + ']';
                }
            }
            else {
                od.src_orderserial = "-";
            }
            od.taxrate = od.taxrate + "%";
            od.amountstr = od.amount.roundTo(2).toThousands();
            od.consignee_displayname = order.src_consignee || order.consignee_realname;
            od._dlvDate = new Date(od.deliverydate || od.src_deliverydate).format("YYYY/MM/DD");
            var v = tplNO.render(od);
            $(".detail").children().remove();
            od.$View = $(v).prependTo(".detail");

            $("#oh-status").addClass(od.status);
            $("#oh-status").vl("<i></i>" + res_sobiz.var.Sale[od.status]);
            $("#oh-order-date").vl(new Date(order.createtime || order.src_orderdate).format("YYYY/MM/DD"));
            $("#oh-clnt-serial").vl(od.src_orderserial||"-");
            if (od.status == 'Pending') {
                btnRemindSaler.vl("提醒卖方确认");
                btnConfirmOrder.vl("确认订单");
            }
            else {
                btnRemindSaler.disable().vl("已确认");
                btnConfirmOrder.disable().vl("已确认");
            }
            renderOrderMX(od);
            View.CheckAuthor(od);
        };
        function renderOrderMX(order) {
            //#region 处理订单明细
            if (order.OrderMX) {
                var tplMX = $(".wx-order-item-tpl").eq(0).remove();
                var gridBody = $("#orderItems").find("ol").eq(0);
                if (gridBody.children("li").length <= 1) {
                    order.am = 0;
                    order.tdlv = 0;
                    order.tstlkin = 0;
                    order.OrderMX.forEach(function (i) {
                        order.am += i.amount;
                        order.tdlv += ($.isNumeric(i.totaldeliveried) ? i.totaldeliveried : 0) * i.price;
                        order.tstlkin += ($.isNumeric(i.totalstockin) ? i.totalstockin : 0) * i.price;

                        var row = tplMX.clone();
                        row.children(".oi-title").vl(i.brand + '【' + i.product + '】');
                        row.children(".oi-model").vl("型号："+i.model);
                        row.children(".oi-productSpec").vl("规格：" + i.src_specification || "-");
                        row.find(".oi-mx-price").vl("单价：" + i.price);
                        row.find(".oi-mx-count").vl("数量："+i.count + '[' + i.unit + ']');
                        row.find(".oi-mx-amount").vl("小计："+i.amount);
                        row.appendTo(gridBody).show();
                    });

                    $("#orderDelivery").children("span").eq(0).vl("已发货：" + (order.tdlv / order.am).formatPercent(2));
                    $("#orderDelivery").children("span").eq(1).vl("已入库：" + (order.tstlkin / order.am).formatPercent(2));
                }
            }
            //#endregion
        };
        function remindSaler() {
            $.getJSON("/Purchase/RemindSaler", { oid: order.idstr }, function (rtn) {
                if (rtn.IsPositive) {
                    btnRemindSaler.vl("已发送提醒").disable();
                }
                else {
                    btnRemindSaler.vl("提醒卖方确认").enable();
                }
            });
        };
        function confirmOrder() {
            $.getJSON("/Sale/ConfirmOrder", { oid: order.idstr }, function (rtn) {
                if (rtn.IsPositive) {
                    btnConfrimOrder.disable().vl("已确认");
                    window.location = window.location;
                }
                else {
                    error("操作失败", ErrFormate(res_sobiz, rtn.ErrorSrc, rtn.ErrorCode, rtn.Error),10);
                }
            });
        };
        onInsecClick = function (ev) {
            $(this).parent(".InfoSection").toggleClass("expand");
        };

        $(function () {
            //获取指定订单的详情
            var oid=getUrlParam("oid");

            //$("#lnkAllNewPurchaseOrders").attr("href", "/Purchase/WxMyOrders");
            //$("#lnkAllNewSaleOrders").attr("href", "/Sale/WxMyOrders");
            if (oid == null) {
                oid = -1;
            }
          
            $(".detail").delegate(".InfoSectionTitle", "click", onInsecClick);

            tplNO = laytpl($("#tplOrderDetail")[0].innerHTML);
           
            btnConfirmOrder = new LiberUI.Button("#btnConfirmOrder")
                                   .on("LCclick", confirmOrder);
            btnRemindSaler = new LiberUI.Button("#btnRemindSaler")
                                   .on("LCclick", remindSaler);
            $("body").on("UserReady", function () {
                $.getJSON("/Trade/GetOrder", { 'oid': oid }, function (rtn) {
                    if (rtn.IsPositive) {
                        order = rtn.Data;
                        renderOrder(order);
                    }
                });
            });
        })
    </script>
</body>
</html>
